using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Data/State/Player/PlayerCoyoteTime", fileName = "PlayerCoyoteTime")]
public class PlayerState_CoyoteTime : PlayerState
{
    [SerializeField] private float coyoteTime;
    [SerializeField] private float playerRunSpeed;

    private float timer;
    //
    public override void Enter()
    {
        base.Enter();
        timer = coyoteTime;
        playerControl.SetUseGravity(false);
    }
    
    //
    public override void Exit()
    {
        base.Exit();
        playerControl.SetUseGravity(true);
        timer = coyoteTime;
    }
    
    //
    public override void LogicUpdate()
    {
        base.LogicUpdate();
        timer -= Time.deltaTime;
        if (timer < 0)
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Fall)]);
        if(playerInput.isInputRoll)
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Roll)]);
        if(playerInput.isInputJump)
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Jump)]);
        // 状态
        if(playerStatusInformation.PlayerIsHit)
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Hit)]);
        if(playerStatusInformation.GetPlayerIsDeath)
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Death)]);
    }
    
    //
    public override void PhysicalUpdate()
    {
        base.PhysicalUpdate();
        animator.SetFloat("Horizontal", playerInput.axesX);
        playerControl.SetVelocityX(playerRunSpeed);
    }
}
